package org.ns.tomdog.server;


import org.ns.tomdog.server.support.HttpProtocolAdapter;

public class Connector implements StartupProgress {

    private ConnectorConfig config; // 连接配置

    private ProtocolHandler protocolHandler;

    private Server server;

    public Connector(ConnectorConfig config, ProtocolHandler protocol, Server server) {
        this.config = config;
        this.server = server;
        try {
            this.protocolHandler = protocol;
            this.protocolHandler.setConnectionConfig(config);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void init() {
        protocolHandler.setProtocolAdapter(new HttpProtocolAdapter(this));
        protocolHandler.init();
    }

    @Override
    public void start() {
        protocolHandler.start();
    }

    public ConnectorConfig getConfig() {
        return config;
    }

    public ProtocolHandler getProtocolHandler() {
        return protocolHandler;
    }

    public Server getServer() {
        return server;
    }
}
